import React, { Component } from 'react'
import { connect } from 'react-redux'
import action from './store/actions/home'
class Home extends Component {
  componentDidMount () {
    this.props.getBannerList()
    this.props.getProList({ limitNum: 1 })
  }
  render() {
    console.log(this.props)
    const { bannerList, proList } = this.props
    return (
      <div>
        home
        <ul>
          {
            bannerList && bannerList.map((item, index) => (
              <li key = { index }>
                <img style={{ width: 100 }} src={ item.img } alt={ item.alt }/>
              </li>
            ))
          }
        </ul>
        <ul>
          {
            proList && proList.map((item, index) => (
              <li key = { index }>
                { item.proname }
              </li>
            ))
          }
        </ul>
      </div>
    )
  }
}

// export default connect((state) => {
//   console.log(state)
//   return {
//     bannerList: state.home.bannerList,
//     proList: state.home.proList
//   }
// }, (dispatch) => {
//   return {
//     getBannerList () {
//       console.log(1)
//       dispatch(action.getBannerListAction)
//     },
//     getProList (params) {
//       dispatch(action.getProListAction(params))
//     }
//   }
// })(Home)
export default connect(({ home: { bannerList, proList } }) => ({ bannerList, proList }),
 (dispatch) => {
  return {
    getBannerList () {
      console.log(1)
      dispatch(action.getBannerListAction)
    },
    getProList (params) {
      dispatch(action.getProListAction(params))
    }
  }
})(Home)

// const obj = {
//   a: {
//     b: {
//       c: 10
//     }
//   }
// }

// const c = obj.a.b.c
// const {c} = obj.a.b
// const { b: {c}} = obj.a
// const { a: { b: {c} }} = obj
